package com.api.core.config;

import com.api.core.filter.RequestValidationFilter;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

import javax.servlet.Filter;

/**
 * 过滤器配置
 */
@Component
@Configuration
public class FilterConfig {

	@Bean
	public FilterRegistrationBean JxtRequestValidationRegistration() {
		FilterRegistrationBean registration = new FilterRegistrationBean();
		registration.setFilter(jxtRequestValidationFilter());
		//小程序-(过滤回调中需再添加一次,用于区分小程序或web请求)
		registration.addUrlPatterns("/linkUser/*");
		registration.addUrlPatterns("/linkUrl/*");
		//web
		registration.addUrlPatterns("/web/*");
		registration.setName("RequestValidationFilter");
		registration.setOrder(1);//优先级，越低越优先
		return registration;
	}

	@Bean
	public Filter jxtRequestValidationFilter (){
		return new RequestValidationFilter();
	}



}
